<?php

namespace App\Admin\Extensions\Table;

use App\Admin\Repositories\UserDonate;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class DonateTable extends LazyRenderable
{
    public function grid(): Grid
    {
        // 获取外部传递的参数
        $user_id = $this->user_id;
        return Grid::make(new UserDonate(), function (Grid $grid) use ($user_id) {
            $grid->disableCreateButton();
            $grid->disableBatchActions();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->model()->where("user_id",$user_id)->where("status",1);
            $grid->column('id')->sortable();
//            $grid->column('user_id');
//            $grid->column('user.nickname','捐赠用户昵称');
            $grid->column('donates.title','目标机构');
            $grid->column('donates.fullname','收件人');
            $grid->column('donates.phone','电话');
            $grid->column('donates.address','收件地址')->limit(15);
            $grid->column('content','捐赠信息')->limit(15);
            $grid->column('platform','快递平台');
            $grid->column('courier_number','快递单号');
//            $grid->column('status','审核状态')->using([0=>"待审核",1=>"审核通过",2=>'审核拒绝'])->label(['default','success','danger']);
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id')->width(3);
//                $filter->like('user.nickname','捐赠用户昵称');
                $filter->like('donates.title','目标机构')->width(3);
                $filter->like('donates.fullname','收件人')->width(3);
                $filter->like('donates.phone','电话')->width(3);
                $filter->like('donates.address','收件地址')->width(3);
                $filter->like('platform','快递平台')->width(3);
                $filter->like('courier_number','快递单号')->width(3);
            });
            $grid->paginate(8);
        });
    }


}
